//
//  SSRegisterController.m
//  textDemo
//
//  Created by Esther on 2017/2/18.
//  Copyright © 2017年 Esther. All rights reserved.
//

#import "SSRegisterController.h"
#import "SSRegisterNextController.h"
#import "SSRegisteInPutView.h"
#import "SSThirdLoginView.h"
#import <UMSocialCore/UMSocialCore.h>

@interface SSRegisterController ()
@property(nonatomic, strong) SSRegisteInPutView *registeInPutView;
@property(nonatomic, strong) SSThirdLoginView *thirdLoginView;
@end

@implementation SSRegisterController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor ss_colorWithRed:242 green:242 blue:242];
    self.title = @"注册";
    
    [self.view addSubview:self.registeInPutView];
    [self.view addSubview:self.thirdLoginView];
    
    #pragma mark - 约束
    __weak typeof (self) weakSelf = self;
    [_registeInPutView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.equalTo(weakSelf.view);
        make.height.mas_equalTo(180);
        
    }];
    
    [_thirdLoginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.registeInPutView.mas_bottom);
        make.left.bottom.right.equalTo(weakSelf.view);
    }];
   
}

#pragma mark -
#pragma mark - 懒加载

- (SSRegisteInPutView *)registeInPutView{
    if (!_registeInPutView) {
        _registeInPutView = [[SSRegisteInPutView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        
        __weak typeof (self) weakSelf = self;
        _registeInPutView.nextControllerBlock = ^(NSDictionary *dict){
            SSRegisterNextController *nextController = [[SSRegisterNextController alloc] init];
            nextController.userInfo = dict;
            [weakSelf.navigationController pushViewController:nextController animated:YES];
            
        };
        
    }
    return _registeInPutView;
}

- (SSThirdLoginView *)thirdLoginView{
    if (!_thirdLoginView) {
        _thirdLoginView = [[SSThirdLoginView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        
        __weak typeof (self) weakSelf = self;
        _thirdLoginView.qqLoginBlock = ^(){
            NSLog(@"qqLoginBlock");
            [weakSelf getAuthWithUserInfoFromWechat];
        };
        
    }
    return _thirdLoginView;
}

// 新浪
- (void)getAuthWithUserInfoFromSina
{
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_Sina currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
            
        } else {
            UMSocialUserInfoResponse *resp = result;
            
            // 授权信息
            NSLog(@"Sina uid: %@", resp.uid);
            NSLog(@"Sina accessToken: %@", resp.accessToken);
            NSLog(@"Sina refreshToken: %@", resp.refreshToken);
            NSLog(@"Sina expiration: %@", resp.expiration);
            
            // 用户信息
            NSLog(@"Sina name: %@", resp.name);
            NSLog(@"Sina iconurl: %@", resp.iconurl);
            NSLog(@"Sina gender: %@", resp.gender);
            
            // 第三方平台SDK源数据
            NSLog(@"Sina originalResponse: %@", resp.originalResponse);
        }
    }];
}

// qq
- (void)getAuthWithUserInfoFromQQ
{
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_QQ currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
            
        } else {
            UMSocialUserInfoResponse *resp = result;
            
            // 授权信息
            NSLog(@"QQ uid: %@", resp.uid);
            NSLog(@"QQ openid: %@", resp.openid);
            NSLog(@"QQ accessToken: %@", resp.accessToken);
            NSLog(@"QQ expiration: %@", resp.expiration);
            
            // 用户信息
            NSLog(@"QQ name: %@", resp.name);
            NSLog(@"QQ iconurl: %@", resp.iconurl);
            NSLog(@"QQ gender: %@", resp.gender);
            
            // 第三方平台SDK源数据
            NSLog(@"QQ originalResponse: %@", resp.originalResponse);
        }
    }];
}

// 微信
- (void)getAuthWithUserInfoFromWechat
{
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
            
        } else {
            UMSocialUserInfoResponse *resp = result;
            
            //登录成功后Push近手机号注册页面
            
            // 授权信息
            NSLog(@"Wechat uid: %@", resp.uid);
            NSLog(@"Wechat openid: %@", resp.openid);
            NSLog(@"Wechat accessToken: %@", resp.accessToken);
            NSLog(@"Wechat refreshToken: %@", resp.refreshToken);
            NSLog(@"Wechat expiration: %@", resp.expiration);
            
            // 用户信息
            NSLog(@"Wechat name: %@", resp.name);
            NSLog(@"Wechat iconurl: %@", resp.iconurl);
            NSLog(@"Wechat gender: %@", resp.gender);
            
            // 第三方平台SDK源数据
            NSLog(@"Wechat originalResponse: %@", resp.originalResponse);
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
